Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(smgp): implements eth_call exchange rate provider #2454

Conversation

jurajpiar
Copy link
Member

Description

Motivation and Context

How Has This Been Tested?

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • Tests for the changes have been added (for bug fixes / features)
  • Requires Activation Code (Hard Fork)
  • Other information:

@jurajpiar jurajpiar force-pushed the juraj/eth_call_stableGasPrice_multi_factory branch 2 times, most recently from 8b99f4a to fd94286 Compare June 7, 2024 10:33
@jurajpiar jurajpiar marked this pull request as ready for review June 7, 2024 10:36
@jurajpiar jurajpiar requested a review from a team as a code owner June 7, 2024 10:36
@jurajpiar jurajpiar force-pushed the juraj/eth_call_stableGasPrice_multi_factory branch from fd94286 to 782ccf8 Compare June 7, 2024 10:55
@jurajpiar jurajpiar force-pushed the juraj/eth_call_stableGasPrice_multi_factory branch 3 times, most recently from be6c603 to 18397fe Compare June 10, 2024 11:14
@jurajpiar jurajpiar force-pushed the juraj/eth_call_stableGasPrice_multi_factory branch from 18397fe to 3dab053 Compare June 10, 2024 12:27
Copy link

sonarcloud bot commented Jun 10, 2024

@jurajpiar jurajpiar requested a review from a team June 10, 2024 13:40
Copy link
Contributor

@fmacleal fmacleal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comments are more recommendations that doesn't prevent the approval. Feel free to follow or not them.

@@ -14,7 +15,7 @@ public class MinGasPriceProviderFactory {
private MinGasPriceProviderFactory() {
}

public static MinGasPriceProvider create(long fixedMinGasPrice, StableMinGasPriceSystemConfig stableMinGasPriceSystemConfig) {
public static MinGasPriceProvider create(long fixedMinGasPrice, StableMinGasPriceSystemConfig stableMinGasPriceSystemConfig, OnChainMinGasPriceProvider.GetContextCallback getContextCallback) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not pass the EthModule directly instead of passing this GetContextCallback?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you pass a callback, that callback is only ever called once the ethmodule exists, as there are no logical paths to it otherwise. When you pass the output of the getEthModule function you then have a runtime circular dependency ie halting problem, because at the time of instantiation of the miner-related objects ethModule does not exist. And to instantiate ethModule you need to pass those miner-related objects.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I agree that this is not very "Java-esque". My JS background shows, and can't think of other non-disruptive way to achieve this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion:

Remove this class and call the new OnChainMinGasPriceProvider(fallbackProvider, config.getOnChainConfig(), getContextCallback) on the MinGasPriceProviderFactory::create method, line 38. This is not adding much.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is out of scope of this PR.


@BeforeEach
public void beforeEach() {
ethModule_mock = mock(EthModule.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion:

You could mock this class directly on the constructor and avoid this repetitive initialization.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know. But the whole point of this is to ensure that your stubs and mocks and what not are always clean for each test case.

ethModule_mock = mock(EthModule.class);
when(ethModule_mock.chainId()).thenReturn("0x21");

fallback_mock = mock(MinGasPriceProvider.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion:

You could mock this class directly on the constructor and avoid this repetitive initialization.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know. But the whole point of this is to ensure that your stubs and mocks and what not are always clean for each test case.

when(fallback_mock.getType()).thenReturn(MinGasPriceProviderType.FIXED);
when(fallback_mock.getMinGasPrice()).thenReturn(fallback_minGasPrice_fake);

onChainMinGasPriceSystemConfig_mock = mock(OnChainMinGasPriceSystemConfig.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion:

You could mock this class directly on the constructor and avoid this repetitive initialization.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know. But the whole point of this is to ensure that your stubs and mocks and what not are always clean for each test case.

@jurajpiar jurajpiar requested a review from fmacleal June 12, 2024 16:43
@Vovchyk Vovchyk merged commit f7a212e into feature/include_stable_minGasPrice_provider Jun 13, 2024
6 checks passed
@Vovchyk Vovchyk deleted the juraj/eth_call_stableGasPrice_multi_factory branch June 13, 2024 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants